﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.MODEL;
using Telerik.Web.UI;

namespace KPIS.GERP.GIMS.APP.APP_UI.Form
{
    public partial class ICM_Inventory_Repair : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        D_IcmInventoryRepair d_repair = new D_IcmInventoryRepair();
        M_IcmInventoryRepair m_repair = new M_IcmInventoryRepair();
        D_SysRepairStatus d_sys_status = new D_SysRepairStatus();
        M_SysRepairStatus m_sys_status = new M_SysRepairStatus();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cmbStatusRepair.DataSource = d_sys_status.GetList();
                cmbStatusRepair.DataBind();
                cmbStatusRepair.Text = "กำลังซ่อมแซม";
                LoadGrid();
                grdInventoryRepair.DataBind();
                btnInsert.OnClientClick = "openStautsAdd()";
            }
        }
        protected void btnInsert_Click(object sender, EventArgs e)
        {
        }
        protected void cmbStatusRepair_OnSelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            LoadGrid();
            grdInventoryRepair.DataBind();

            Int32 count = 0;
            count = grdInventoryRepair.Items.Count;
            Int32 i;

            if (count > 0)
            {
                if (cmbStatusRepair.Text == "กำลังซ่อมแซม")
                {
                    grdInventoryRepair.Items[0].Enabled = true;
                }
                else
                {
                    for (i = 0; i < count; i++)
                    {
                        grdInventoryRepair.Items[i].Enabled = false;
                    }
                }
            }
        }
        protected void grdInventoryRepair_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            LoadGrid();
        }
        protected void grdInventoryRepair_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (e.CommandName == "DataDelete")
            {
                M_IcmInventoryRepair info = d_repair.GetListFillBySeq(cn.ConvertNullInt(grdInventoryRepair.Items[e.Item.ItemIndex]["icm_repair_seq"].Text));
                m_repair.icm_repair_seq = info.icm_repair_seq;
                m_repair.record_status = "D";
                m_repair.updated_by = cn.UserID;
                m_repair.updated_when = DateTime.Now;
                d_repair.Delete_Inventory_Repair(m_repair);
                LoadGrid();
                grdInventoryRepair.DataBind();
            }
        }
        private void LoadGrid()
        {
            string strRepairCode = d_sys_status.GetListFillByName(cmbStatusRepair.Text);
            grdInventoryRepair.DataSource = d_repair.GetListFillByStatusRepairCode(strRepairCode);
        }
        protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            LoadGrid();
            grdInventoryRepair.Rebind();
        }
    }
}
